package com.policenacorp.ejb.impl;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import com.policenacorp.ejb.bean.local.EJBContextBeanLocal;
import com.policenacorp.ejb.bean.local.InjetaSetterBeanLocal;
import com.policenacorp.ejb.bean.remote.InjetaSetterBeanRemote;

@Stateless
public class InjetaSetterBusiness implements InjetaSetterBeanLocal, InjetaSetterBeanRemote {

    private EJBContextBeanLocal ejbContextBeanLocal;

    @EJB
    public void setEjbContextBeanLocal(final EJBContextBeanLocal ejbContextBeanLocal) {
	System.out.println("Conteiner passou dentro deste metodo para injetar o ejb.");
	this.ejbContextBeanLocal = ejbContextBeanLocal;
    }

    @Override
    public void testeBeanInjetado() {
	final boolean ejbContextNaoNulo = ejbContextBeanLocal != null;
	if (ejbContextNaoNulo) {
	    final StringBuilder sBuilder = new StringBuilder();
	    sBuilder.append("Injecao funcionou!");
	    sBuilder.append(String.format("\nNome da classe do EJB: %s", ejbContextBeanLocal.getClass()
		    .getCanonicalName()));
	    System.out.println(sBuilder);
	} else {
	    System.out.println("Teste falhou, ejb context nao injetado.");
	}
    }

}
